package com.example.classrecord;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

//this is not a test
// testing...
//another test
//test 4
public class AddClass extends Activity {
	Button save, clear;
	EditText name, number, student;
	DataHandler handler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_class);
		save = (Button) findViewById(R.id.saveBtn);
		clear = (Button) findViewById(R.id.clearBtn);
		name = (EditText) findViewById(R.id.addClassName);
		number = (EditText) findViewById(R.id.addClassNum);
		student = (EditText) findViewById(R.id.addClassStudent);
		
		/** On save button click, opens database and inserts data then closes the database **/
		
		save.setOnClickListener(new OnClickListener(){
			
			@Override
			public void onClick(View v){
				
				String getName = name.getText().toString();
				String getNumber = number.getText().toString();
				String getStudent = student.getText().toString();
				handler = new DataHandler(getBaseContext());
				handler.open();
				long id = handler.insertData(getName, getNumber, getStudent);
				Toast.makeText(getBaseContext(),"Data: " + getName + " saved!", Toast.LENGTH_SHORT).show();
				handler.close();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.add_class, menu);
		return true;
	}
	
	public void clearBtn(View v){

		/** Clear's the EditText **/
		clear.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){
				name.setText("");
				number.setText("");
				student.setText("");
			}
		});	
	}
}
